<?php
/**
 * +--------------------------------------------------------+
 * @Created by Phpstorm.
 * @Category WebSocketClient.php
 * @Depiction
 * @Author hwy <429208948@qq.com>
 * @Date 2022/7/4  10:51
 * +--------------------------------------------------------+
 */

namespace App\Services\Swoole;


class WebSocketClient
{
    const WEB_SOCKET = 'ws://127.0.0.1:9502';

    public function handle($params = [])
    {
        $ws = new \App\Util\WebSocketClient(self::WEB_SOCKET);

        var_dump($ws->ping());

        $ws->send(json_encode($params));
        $frame = $ws->recv();
        echo "收到服务器响应数据：" . $frame->playload . PHP_EOL;
        var_dump($ws->close());
        return $frame->playload;
    }

}
